const KoaRouter = require('koa-router');
const router = new KoaRouter({prefix: process.env.API_PREFIX});
const adminController = require('../controllers/adminController.js');
const authController = require('../controllers/authController.js');
const authMiddleware = require('../middleware/authMiddleware.js');
const videoController = require('../controllers/videoController.js');
const webhookController = require('../controllers/webhookController.js');
const userController = require('../controllers/userController.js');
const settingController = require('../controllers/settingController.js');
const statisticsController = require('../controllers/statisticsController.js');
const messageController = require('../controllers/messageController.js');
const userMiddleware = require('../middleware/userMiddleware.js');
const orderController = require('../controllers/orderController.js');

router.post('/admin', authMiddleware, adminController.addAdmin);
router.post('/admin/adminLogout', adminController.adminLogout);
router.post('/admin/delete', authMiddleware, adminController.deleteAdmin);
router.put('/admin', authMiddleware, adminController.updateAdmin);
router.put('/admin/my', authMiddleware, adminController.adminUpdateMyInfo);
router.post('/admin/updateMyProfile', authMiddleware, adminController.updateMyProfile);
router.post('/admin/updateMyPassword', authMiddleware, adminController.updateMyPassword);
router.post('/admin/login', adminController.loginAdmin);
router.get('/admin/info', adminController.adminInfo);
router.get('/admin/getAdminListByPage', adminController.getAdminListByPage);
router.get('/refreshToken', authController.refreshToken);

router.post('/video',authMiddleware, videoController.addVideo);
router.delete('/video/:id', authMiddleware, videoController.deleteVideo);
router.put('/video', authMiddleware, videoController.updateVideo);
router.get('/video/list', videoController.getVideoListByPage);
router.get('/video/reStoreVideoList', videoController.reStoreVideoList);
router.get('/videos', videoController.getAllVideos);
router.get('/video/:filename', videoController.getVideo);

router.post('/user', userController.addUser);
router.post('/user/logout', userController.userLogout);
router.delete('/user/:id', authMiddleware, userController.deleteUser);
router.put('/user', authMiddleware, userController.updateUser);
router.post('/user/updateMyPassword', authMiddleware, userController.updateMyPassword);
router.post('/user/retrieveUserPassword', userController.retrieveUserPassword);
router.post('/user/login', userController.loginUser);
router.get('/user/info', userController.userInfo);
router.get('/user/list', userController.getUserListByPage);
router.get('/user/:id', authMiddleware, userController.getUserById);
router.get('/refreshUserToken', authController.refreshUserToken);
router.get('/getVerificationCode/:email', userController.getVerificationCode);

router.post('/webhooks/server', webhookController.server);

router.post('/syncDatabase', settingController.syncDatabase)

router.get('/getStatisics/:year', authMiddleware, statisticsController.getStatisics);

router.post('/message', messageController.addMessage);
router.post('/message/userAddMessage', userMiddleware,messageController.userAddMessage);
router.delete('/message/:id', authMiddleware, messageController.deleteMessage);
router.put('/message', authMiddleware, messageController.updateMessage);
router.get('/message/list', messageController.getMessageListByPage);
router.get('/message/:id', authMiddleware, messageController.getMessageById);

router.post('/addOrder', userMiddleware, orderController.addOrder);
router.post('/notify', orderController.notify);
router.delete('/order/:id', orderController.deleteOrder);
router.get('/order/list', orderController.getOrderListByPage);
router.get('/order/:id', orderController.getOrderStatus);
router.put('/order/cancel', orderController.cancelOrder);

router.get('/refreshUserToken', authController.refreshUserToken);

module.exports = router;
